package cn.wind.xboot.module.web.controller;

import cn.wind.xboot.core.res.ApiResult;
import cn.wind.xboot.logic.entity.StoreSteelyard;
import cn.wind.xboot.logic.service.IStoreSteelyardService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;

/**
 * 智能秤管理
 * @author WangHao
 * @date 2019-02-18
 */
@Slf4j
@Controller
@RequestMapping("storeSteelyard")
public class StoreSteelyardController {
    @Autowired
    private IStoreSteelyardService storeSteelyardService;
    /**
     * 添加智能秤的唯一识别码
     * @param storeSteelyard
     * @return
     */
    @RequestMapping("/add")
    @ResponseBody
    public ApiResult add(StoreSteelyard storeSteelyard,HttpServletResponse httpServletResponse){
        httpServletResponse.setHeader("Access-Control-Allow-Origin", "*");
        StoreSteelyard s = storeSteelyardService.findByDeviceToken(storeSteelyard.getDeviceToken());
        if (s!=null){
            return ApiResult.Custom().failure(900440,"该智能秤已存在");
        }else {
            storeSteelyardService.saveOrUpdate(storeSteelyard);
            return ApiResult.Custom().success("该智能秤不存在");
        }
    }
}
